GdkGLContext: Fix damage computation with buffer_age
authorTimm Bäder <mail@baedert.org>
Fri, 30 Nov 2018 12:14:00 +0000 (13:14 +0100)
committerTimm Bäder <mail@baedert.org>
Sun, 2 Dec 2018 12:25:43 +0000 (13:25 +0100)
As per the spec:

> The back buffer can
> either be reported as invalid (has an age of 0) or it may be
> reported to contain the contents from n frames prior to the
> current frame.

So a  buffer age of 1 means that the buffer was used in the last frame.
We were handling buffer_age==1 the same as buffer_age==0, i.e. we
returned the full damage for the surface.

[1] https://www.khronos.org/registry/EGL/extensions/EXT/EGL_EXT_buffer_age.txt

gdk/wayland/gdkglcontext-wayland.c
gdk/x11/gdkglcontext-x11.c

index 1e1259bbac0b2eeb79244db36ce2991d34002bf0..75c4acfd872a7d94462cfd30dcff23f44ab8ace4 100644 (file)
@@ -170,7 +170,7 @@ gdk_wayland_gl_context_get_damage (GdkGLContext *context)
     {
       GdkGLContext *shared;
       GdkWaylandGLContext *shared_wayland;
-     
+
       shared = gdk_gl_context_get_shared_context (context);
       if (shared == NULL)
         shared = context;
@@ -182,20 +182,29 @@ gdk_wayland_gl_context_get_damage (GdkGLContext *context)
       eglQuerySurface (display_wayland->egl_display, egl_surface,
                        EGL_BUFFER_AGE_EXT, &buffer_age);
 
-      if (buffer_age == 2)
-        {
-          if (context->old_updated_area[0])
-            return cairo_region_copy (context->old_updated_area[0]);
-        }
-      else if (buffer_age == 3)
+      switch (buffer_age)
         {
-          if (context->old_updated_area[0] &&
-              context->old_updated_area[1])
-            {
-              cairo_region_t *damage = cairo_region_copy (context->old_updated_area[0]);
-              cairo_region_union (damage, context->old_updated_area[1]);
-              return damage;
-            }
+          case 1:
+            return cairo_region_create ();
+            break;
+
+          case 2:
+            if (context->old_updated_area[0])
+              return cairo_region_copy (context->old_updated_area[0]);
+            break;
+
+          case 3:
+            if (context->old_updated_area[0] &&
+                context->old_updated_area[1])
+              {
+                cairo_region_t *damage = cairo_region_copy (context->old_updated_area[0]);
+                cairo_region_union (damage, context->old_updated_area[1]);
+                return damage;
+              }
+            break;
+
+          default:
+            ;
         }
     }
 
index 0c8970fd5c9dd0bc1b3fddc9fe38a6ee355a9623..5de9d55cf0142e31d9680cb3352bd2b807d36243 100644 (file)
@@ -201,31 +201,41 @@ gdk_x11_gl_context_get_damage (GdkGLContext *context)
     {
       GdkGLContext *shared;
       GdkX11GLContext *shared_x11;
-     
+
       shared = gdk_gl_context_get_shared_context (context);
       if (shared == NULL)
         shared = context;
       shared_x11 = GDK_X11_GL_CONTEXT (shared);
 
       gdk_gl_context_make_current (shared);
-      glXQueryDrawable(dpy, shared_x11->attached_drawable,
-                      GLX_BACK_BUFFER_AGE_EXT, &buffer_age);
+      glXQueryDrawable (dpy, shared_x11->attached_drawable,
+                        GLX_BACK_BUFFER_AGE_EXT, &buffer_age);
 
-      if (buffer_age == 2)
-        {
-          if (context->old_updated_area[0])
-            return cairo_region_copy (context->old_updated_area[0]);
-        }
-      else if (buffer_age == 3)
+      switch (buffer_age)
         {
-          if (context->old_updated_area[0] &&
-              context->old_updated_area[1])
-            {
-              cairo_region_t *damage = cairo_region_copy (context->old_updated_area[0]);
-              cairo_region_union (damage, context->old_updated_area[1]);
-              return damage;
-            }
+          case 1:
+            return cairo_region_create ();
+            break;
+
+          case 2:
+            if (context->old_updated_area[0])
+              return cairo_region_copy (context->old_updated_area[0]);
+            break;
+
+          case 3:
+            if (context->old_updated_area[0] &&
+                context->old_updated_area[1])
+              {
+                cairo_region_t *damage = cairo_region_copy (context->old_updated_area[0]);
+                cairo_region_union (damage, context->old_updated_area[1]);
+                return damage;
+              }
+            break;
+
+          default:
+            ;
         }
+
     }
 
   return GDK_GL_CONTEXT_CLASS (gdk_x11_gl_context_parent_class)->get_damage (context);